Skip to content

Conversation

@PawelLipski
Copy link
Collaborator

@PawelLipski PawelLipski commented Nov 3, 2025

Based on PR #1528

Chain of upstream PRs as of 2025-11-14

  • Add get_worktrees() and get_worktree_path() methods to GitOperations
  • Modify traverse to cd into worktrees where branches are checked out
  • Cache worktree information to avoid repeated git worktree list calls
  • Add informative messages when changing directories to worktrees
  • Add comprehensive tests for worktree handling including detached HEAD cases
  • Add integration test for traverse with multiple worktrees

Fixes #1522

TBD: how about checkout from other commands like git machete go? ➡️ leave as is, there's no easy way to switch shell's wd from inside Python process; just fail

TODO: mention in docs ➡️ done

@PawelLipski PawelLipski added this to the v3.37.1 milestone Nov 3, 2025
@PawelLipski PawelLipski self-assigned this Nov 3, 2025
@PawelLipski PawelLipski linked an issue Nov 3, 2025 that may be closed by this pull request
@PawelLipski PawelLipski added the traverse Relates to how tree traversal is performed label Nov 3, 2025
@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 98.64865% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.61%. Comparing base (a4f4137) to head (64f2b56).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
git_machete/git_operations.py 97.56% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1524      +/-   ##
===========================================
- Coverage    98.62%   98.61%   -0.01%     
===========================================
  Files           26       26              
  Lines         4278     4344      +66     
  Branches       812      828      +16     
===========================================
+ Hits          4219     4284      +65     
  Misses          38       38              
- Partials        21       22       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PawelLipski PawelLipski force-pushed the improve/1522-worktree-switch-traverse branch 2 times, most recently from 219c5ed to cae8edf Compare November 6, 2025 13:37
@PawelLipski PawelLipski marked this pull request as ready for review November 6, 2025 14:19
@lsierant
Copy link

lsierant commented Nov 7, 2025

@PawelLipski I've tested it locally and works flawlessly! Thanks!

The only thing (which I'm not sure it should addressed) is a slight UX/flow difference when the branch in a worktree is dirty and cannot be manipulated (e.g. rebased).

Without the worktree, after something fails when traversing, git-machete leaves the current tree in the currently processing branch, so it's easy to fix it and proceed with another traverse.

With worktrees, it cd into a worktree but when it exists with an error, you're still in the current worktree. Slightly annoying, but not blocking!

Worth considering having this UX unified.

@PawelLipski
Copy link
Collaborator Author

With worktrees, it cd into a worktree but when it exists with an error, you're still in the current worktree. Slightly annoying, but not blocking!

Yeah, I think it's going to be hard to work around, that's more of an OS limitation (Linux/macOS/Windows) — a process can't change its parent's working directory (Reddit).

I'll instead make traverse print a warning (as the last thing in the output) which encourages the user to cd to the worktree corresponding to the checked out branch. The warning will be always printed if the initial WD doesn't correspond to the checked out branch, regardless of whether traverse failed or finished successfully.

@PawelLipski PawelLipski force-pushed the improve/1522-worktree-switch-traverse branch 9 times, most recently from 07fd8ec to 34652bc Compare November 12, 2025 16:27
@PawelLipski PawelLipski force-pushed the improve/1522-worktree-switch-traverse branch 2 times, most recently from 36e601c to 6e3d672 Compare November 12, 2025 18:24
- Add get_worktrees() and get_worktree_path() methods to GitOperations
- Modify traverse to cd into worktrees where branches are checked out
- Cache worktree information to avoid repeated git worktree list calls
- Add informative messages when changing directories to worktrees
- Add comprehensive tests for worktree handling including detached HEAD cases
- Add integration test for traverse with multiple worktrees

Fixes #1522
@PawelLipski PawelLipski marked this pull request as draft November 14, 2025 11:59
@PawelLipski PawelLipski changed the base branch from develop to refactor/rename-worktree-git-ops November 14, 2025 11:59
@PawelLipski PawelLipski force-pushed the improve/1522-worktree-switch-traverse branch from 41cb114 to 64f2b56 Compare November 14, 2025 11:59
@PawelLipski PawelLipski marked this pull request as ready for review November 14, 2025 11:59
Base automatically changed from refactor/rename-worktree-git-ops to develop November 14, 2025 16:31
@PawelLipski PawelLipski merged commit 64f2b56 into develop Nov 17, 2025
12 checks passed
@PawelLipski PawelLipski deleted the improve/1522-worktree-switch-traverse branch November 17, 2025 09:20
@PawelLipski
Copy link
Collaborator Author

To be released as v3.37.1 soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

traverse Relates to how tree traversal is performed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

traverse cannot work with branches already checked out in worktrees

4 participants